<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" :isHaveExport="false" @toAdd="add_data"
        @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" :searchData="userSearchData" @sendUserSearch="receive_search">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" stripe v-loading="loading" header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" class="tc" width="35"></el-table-column>
          <el-table-column label="用户头像" min-width="70">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用户信息" min-width="110">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{ scope.row.nickname || "----" }}</span>
                </div>
                <div>
                  <span>用户名：</span>
                  <span>{{ scope.row.username || "----" }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="讲师头像" min-width="70">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.tid_avatar)" alt />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="讲师信息" min-width="110">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>讲师昵称：</span>
                  <span>{{ scope.row.tid_cn || "----" }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="评价信息" min-width="160">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>标签：</span>
                  <span>{{ scope.row.label }}</span>
                </div>
                <div>
                  <span>内容：</span>
                  <span>{{ scope.row.content }}</span>
                </div>

              </div>
            </template>
          </el-table-column>

          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button :loading="$store.state.isLoading" size="mini" @click="editbtn(scope.row)" type="primary">编辑</el-button>
                <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="deletebtn(scope.row.id)">删除</el-button>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog :close-on-click-modal="false" title="编辑" class="tl size_13" width="800px" :visible.sync="dialogFormVisible">
      <el-form :model="live_single" ref="form" label-width="120px">
        <el-form-item label="用户：" prop="uid" v-if="is_edit == false">
          <el-col :span="12">
            <el-input placeholder="请选择用户" v-model="live_single.username" :disabled="true" clearable></el-input>
          </el-col>
          <el-col :span="5" :offset="1">
            <el-button :loading="$store.state.isLoading" size="medium" type="primary" @click="xzshop('xz_user')">选择用户</el-button>
          </el-col>
        </el-form-item>
        <el-form-item label="讲师：" prop="uid" v-if="is_edit == false">
          <el-col :span="12">
            <el-input placeholder="请选择讲师" v-model="live_single.tid_cn" :disabled="true" clearable></el-input>
          </el-col>
          <el-col :span="5" :offset="1">
            <el-button :loading="$store.state.isLoading" size="medium" type="primary" @click="xzshop('xz_tutor')">选择讲师</el-button>
          </el-col>
        </el-form-item>

        <!-- <el-form-item label="审核：" v-if="is_edit == true">
          <el-col :span="14">
            <el-radio-group v-model="live_single.is_check">
              <el-radio label="0">未审核</el-radio>
              <el-radio label="1">已审核</el-radio>
              <el-radio label="2">驳回</el-radio>
            </el-radio-group>
          </el-col>
        </el-form-item> -->
        <!-- <el-form-item label="订单号：">
          <el-col :span="12">
            <el-input type="text" :rows="6" clearable placeholder="请输入订单号" v-model="live_single.oid" autocomplete="off"></el-input>
          </el-col>
        </el-form-item> -->
        <!-- <el-form-item label="图片">
          <el-form class="clearfix" label-position="right" label-width="120px">
            <el-col :span="24" class="mar_bottom_20">
              <el-col :span="24">
                <uploadpic :file="fileList" :width="150" :height="150" :real_width="150" :real_height="150" :is_more="true" @send_pic="onSuccess"
                    @del_pic="del_pic"></uploadpic>
              </el-col>
            </el-col>
          </el-form>
        </el-form-item> -->

        <el-form-item label="内容：">
          <el-col :span="12">
            <el-input type="textarea" :rows="6" clearable placeholder="请输入内容" v-model="live_single.content" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="标签：">
          <el-col :span="20">
            <!-- <el-checkbox-group v-model="sellabel">
              <el-checkbox :label="item" v-for="(item, i) in label_list" :key="i"></el-checkbox>
            </el-checkbox-group> -->
            <el-input type="text" clearable placeholder="请输入标签" v-model="live_single.label" autocomplete="off">
              <span slot="append">用@间隔</span>
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item>
          <el-button :loading="$store.state.isLoading" type="primary" @click="editlive(live_single)">编 辑</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <component :is="current" :show="shows" role="driver" :isAll="false" showType="list" @sendShop="getSend" @isshow="getShow"></component>
  </div>
</template>
<script>
import { dz_tutor_comment } from "../../assets/js/searchData/searchData"; //引入搜索的数据

import xz_tutor from "@/components/tutor/tutor_xz.vue";
import xz_user from "@/components/currency/xz_user.vue";
import uploadpic from "@/components/page/pic/up_pic";
export default {
  data () {
    return {
      sellabel: [], //选中的标签
      label_list: [],
      fileList: [],

      userSearchData: dz_tutor_comment,
      current: "xz_tutor",
      shows: false,
      is_edit: false,
      dialogFormVisible: false,
      live_single: {},
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},
      multipleSelection: [],
      showCity: true
    };
  },
  components: {
    xz_tutor,
    xz_user,
    uploadpic
  },
  methods: {
    onSuccess (shop_list) {
      this.fileList = this.fileList.concat(shop_list);
      //   this.live_single.piclink = pic;
    },
    del_pic (val) {
      this.fileList.splice(val, 1);
    },
    getShow (val) {
      this.shows = val;
    },
    getSend (row) {
      if (this.current == "xz_user") {
        this.live_single.username = row.username;
        this.live_single.uid = row.uid;
      } else if (this.current == "xz_tutor") {
        this.live_single.tid_cn = row.title;
        this.live_single.tid = row.id;
      }
    },
    xzshop (val) {
      this.current = val;
      this.shows = true;
    },
    sorta (a, b) {
      return b - a;
    },
    sortNew (index, row) {
      var params = {};
      params = row;
      params.id = row.id;
      params.sort = row.sort;
      this.$api.getDz.edit_tutor_comment(params).then(res => {
        if (res.data.code == 200 && res.data.result) {
          return;
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    deleteAll () {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思"
        }).then(willDelete => {
          if (willDelete.value) {
            this.$api.getDz
              .del_tutor_comment({ id_str: str })
              .then(res => {
                if (res.data.code == 200) {
                  this.$swal("删除成功！", res.data.result, "success");
                  this.getNewsAll(this.searchAll);
                } else {
                  this.$swal("删除失败！", res.data.result, "success");
                  this.getNewsAll(this.searchAll);
                }
              });
          }
        });
      }
    },
    deletebtn (id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          this.$api.getDz.del_tutor_comment({ id_str: id }).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            }
          });
        }
      });
    },
    add_data () {
      this.live_single = {};
      // this.fileList = [];
      // this.sellabel = [];
      if (this.$route.query.id) {
        this.live_single.tid = this.$route.query.id;
        this.live_single.tid_cn = this.$route.query.name;
      }
      this.is_edit = false;
      this.dialogFormVisible = true;
    },

    getIs (val, row) {
      this.is_edit = true;
      var params = {};
      params = row;
      params.id = row.id;
      params.show = val;
      this.editlive(params);
    },

    editlive (item) {
      var params = {};
      var piclink = "";
      // var label = "";
      // if (this.fileList && this.fileList.length > 0) {
      //   this.fileList.forEach((item, i) => {
      //     piclink = piclink + item.piclink + "@";
      //   });
      // }
      // piclink = piclink.substring(0, piclink.length - 1);
      // if (this.sellabel && this.sellabel.length > 0) {
      //   this.sellabel.forEach((item, i) => {
      //     label = label + item + "@";
      //   });
      // }
      // label = label.substring(0, label.length - 1);
      params = item;
      // params.piclink = piclink;
      // params.label = label;
      if (this.is_edit == false) {
        params.show = 1;
        this.$api.getDz.add_tutor_comment(params).then(res => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      } else {
        this.$api.getDz.edit_tutor_comment(params).then(res => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      }
    },
    editbtn (item) {
      this.is_edit = true;
      // this.fileList = [];
      // this.sellabel = [];
      this.live_single = JSON.parse(JSON.stringify(item));
      // var arr = this.live_single.piclink.split("@");
      // arr.forEach((pic, i) => {
      //   var obj = {
      //     piclink: pic
      //   };
      //   this.fileList.push(obj);
      // });
      // this.live_single.label.forEach((lab, i) => {
      //   this.sellabel.push(lab.content);
      // });
      // this.live_single.star = Number(this.live_single.star);
      // console.log(this.live_single);
      //  this.live_single.i
      this.dialogFormVisible = true;
    },

    receive_search (obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll (data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      if (this.$route.query.id) {
        params.tid = this.$route.query.id
      }
      this.$api.getDz.get_tutor_comment(params).then(res => {
        if (res.data.code == 200) {
          res.data.result.data.forEach((item, i) => {
            res.data.result.data[i].star = Number(item.star);
          });
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },

    reload () {
      this.getNewsAll(this.searchAll);
    },

  },
  beforeCreate () { },
  created () {
    this.getNewsAll();
  },
  computed: {}
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
</style>
